<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>控制图</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="检测项目列表">
<meta name="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" type="text/css" href="../../script/js/layui/css/layui.css" media="all">
<script type="text/javascript" src="../../script/js/layui/layui.js"></script>
<script type="text/javascript" src="../../mes/js/vue.min.js"></script>
<script type="text/javascript" src="../../mes/js/vue-resource.min.js"></script>
<script type="text/javascript" src="../../script/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../script/js/lodash.min.js"></script>
<style type="text/css">
html, body{height: 100%;}
.div-chart{ height: 60%;}
.div-chart .layui-tab-content{height: calc(100% - 41px); padding: 0;}
.div-chart .layui-tab-item{height: 100%;}
.div-grid{ height: 40%;}
.layui-tab{height: 100%; margin: 0;}
.div-grid .layui-table-view{margin: 0;}
#sampleDataTable{height: 100%;}
.graphFrame{height: 100%; width: 100%; border: 0 none;}
.layui-laypage a{
	color: black;
}
</style>
</head>
<body id="controlChart">
<div class="div-chart">
	<div class="layui-tab layui-tab-card" lay-filter="tabFilter">
		<ul class="layui-tab-title">
			<li class="layui-this">控制图</li>
			<li v-if="checkitemType === 'variables'">cpk分析图</li>
			<li v-if="checkitemType === 'variables'">样本运行图</li>
			<li v-if="checkitemType === 'variables'">均值运行图</li>
			<li v-if="checkitemType === 'variables'">正态检验图</li>
			<li v-if="checkitemType === 'variables'">CPK趋势图</li>
			<!-- <li v-if="checkitemType === 'variables'">CPK周期趋势图</li> -->
			<li v-if="checkitemType === 'counting'">柏拉图</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show"><iframe class="graphFrame" id="control" name="control"></iframe></div>
			<div class="layui-tab-item" v-if="checkitemType === 'variables'">
				<iframe class="graphFrame" id="cpkAnalysisChart" name="cpkAnalysisChart" src=""></iframe>
			</div>
			<div class="layui-tab-item" v-if="checkitemType === 'variables'">
				<iframe class="graphFrame" id="sampleRunning" name="sampleRunning"></iframe>
			</div>
			<div class="layui-tab-item" v-if="checkitemType === 'variables'">
				<iframe class="graphFrame" id="averageRunning" name="averageRunning"></iframe>
			</div>
			<div class="layui-tab-item" v-if="checkitemType === 'variables'">
				<iframe class="graphFrame" id="normalCheckChart" name="normalCheckChart" src=""></iframe>
			</div>
			<div class="layui-tab-item" v-if="checkitemType === 'variables'">
				<iframe class="graphFrame" id="cpkPredictChart" name="cpkPredictChart" src=""></iframe>
			</div>
			<div class="layui-tab-item" v-if="checkitemType === 'variables'">
				<iframe class="graphFrame" id="cpkCyclePredictChart" name="cpkCyclePredictChart" src=""></iframe>
			</div>
			<div class="layui-tab-item" v-if="checkitemType === 'counting'">
				<iframe class="graphFrame" id="plato" name="plato"></iframe>
			</div>
		</div>
	</div>
</div>
<div class="div-grid">
	<div class="layui-btn-group">
		<button class="layui-btn layui-btn-warm" @click="openAddData">新增</button>
	  	<button class="layui-btn" @click="openSetConfigDiv">设置标准上下限</button>
	  	<button class="layui-btn layui-btn-danger" @click="openCalControlDiv">设置控制上下限</button>
	  	<button class="layui-btn layui-btn-normal" @click="executeCheckRule">执行判异规则</button>
	  	<button class="layui-btn layui-btn-danger" @click="openSelectData">数据筛选</button>
	  	<button class="layui-btn layui-btn-warm" @click="doExportExcel">导出</button>
	</div>
	<table class="layui-hide" id="sampleDataTable" lay-filter="sampleDataFilter"></table>
</div>
</body>
<div style="display: none;" id="setConfigDiv">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label input-lab">规格上限（USL）</label> 
				<div class="layui-input-inline">
					<input type="text" class="layui-input input-cls" id="setusl">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label input-lab">规格下限（LSL）</label> 
				<div class="layui-input-inline input-cls">
					<input type="text" class="layui-input input-cls" id="setlsl">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label input-lab">目标值</label> 
				<div class="layui-input-inline input-cls">
					<input type="text" class="layui-input input-cls" id="settarget">
				</div>
			</div>
		</div>
		<div class="layui-form-item" style="text-align: center;">
			<button type="button"  class="layui-btn" @click="savSetConfig">保存</button>
		</div>
</div>
<div style="display: none;" id="calControlDiv">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label input-lab">控制上限（UCL）</label> 
				<div class="layui-input-inline">
					<input type="text" class="layui-input input-cls" id="setucl">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label input-lab">控制下限（LCL）</label> 
				<div class="layui-input-inline input-cls">
					<input type="text" class="layui-input input-cls" id="setlcl">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label input-lab">目标值</label> 
				<div class="layui-input-inline input-cls">
					<input type="text" class="layui-input input-cls" id="setcltarget">
				</div>
			</div>
		</div>
		<div class="layui-form-item" style="text-align: center;">
			<button type="button"  class="layui-btn" @click="savCalControl">保存</button>
			<button type="button"  class="layui-btn layui-btn-warm" @click="calControl">重新计算</button>
		</div>
</div>
<div style="display: none;" id="viewStateDiv">
	<div class="layui-row layui-col-space1" style="height: 30px;width: 600px;">
	    <div class="layui-col-md6" style="text-align: center;line-height: 30px;border: 1px solid black;">
	     		样本数据
	    </div>
	    <div class="layui-col-md6" style="text-align: center;line-height: 30px;border: 1px solid black;">
	      		失控处理
	    </div>
	    <!-- 
	    <div class="layui-col-md4" style="text-align: center;line-height: 30px;border: 1px solid black;">
	      		审核结果
   		</div>
   		 -->
	</div>
	<div class="layui-row layui-col-space1" style="height: 300px;width: 600px;">
	    <div class="layui-col-md6" style="height: 300px;border: 1px solid black;word-break: break-all; word-wrap:break-word;" id="sampleDataC">
	    </div>
	    <div class="layui-col-md6" style="height: 300px;border: 1px solid black;word-break: break-all; word-wrap:break-word;" id="errorDataC">
	    </div>
	    <!-- 
	    <div class="layui-col-md4" style="height: 300px;border: 1px solid black;" id="handleResultC">
   		</div>
   		-->
	</div>
</div>
<div style="display: none;" id="handleErrorDiv">
		<div class="layui-form-item layui-form-text">
			 <label class="layui-form-label">失控原因：</label>
			 <div class="layui-input-block">
			 	<textarea placeholder="请输入内容" class="layui-textarea" id="unControlReason" style="width:360px; height:100px; "></textarea>
			 </div>
		</div>
		<div class="layui-form-item layui-form-text">
			 <label class="layui-form-label">处理措施：</label>
			 <div class="layui-input-block">
			 	<textarea placeholder="请输入内容" class="layui-textarea" id="handleMethod" style="width:360px; height:100px; "></textarea>
			 </div>
		</div>
		<div class="layui-form-item" style="text-align: center;">
			<button type="button"  class="layui-btn" @click="handleError">确定</button>
		</div>
</div>
<div style="display: none;" id="selectDataDiv">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label input-lab" style="width: 150px;">抽检时间范围</label> 
			<div class="layui-input-inline">
				<input type="text" class="layui-input input-cls" style="width: 300px;" id="select_check_date" name="select_check_date" readonly="readonly">
			</div>
		</div>
		<div class="layui-form-item" align="">
			<label class="layui-form-label input-lab" style="width: 150px;">是否为样本</label>
	    	<div class="layui-inline layui-form" >
	    			<input type="radio" name="select_isSampleData" id="select_isSampleData" value="1" title="是">
      				<input type="radio" name="select_isSampleData" id="select_isSampleData" value="0" title="否" checked="">
	    	</div>
	    </div>
	    <div class="layui-form-item" align="">
	    	<label class="layui-form-label input-lab" style="width: 150px;">设备</label>
	    	<div class="layui-inline layui-form" >
		    	<input type="text" class="layui-input input-cls" id="select_remark1" name="select_remark1">
	    	</div>
	    </div>
	    <div class="layui-form-item" align="">
	    	<label class="layui-form-label input-lab" style="width: 150px;">位置</label>
	    	<div class="layui-inline layui-form" >
		    	<input type="text" class="layui-input input-cls" id="select_remark2" name="select_remark2">
	    	</div>
	    </div>
	    <div class="layui-form-item" align="">
	    	<label class="layui-form-label input-lab" style="width: 150px;">管号</label>
	    	<div class="layui-inline layui-form" >
		    	<input type="text" class="layui-input input-cls" id="select_remark3" name="select_remark3">
	    	</div>
	    </div>
		<div class="layui-form-item" style="text-align: center;">
			<button type="button"  class="layui-btn" @click="searchSelectData">查询</button>
		</div>
	</div>
</div>
<div style="display: none;" id="addDataDiv">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label input-lab">抽检时间</label> 
			<div class="layui-input-inline">
				<input type="text" class="layui-input input-cls" id="add_check_date" name="add_check_date" readonly="readonly">
			</div>
		</div>
	</div>
	<div class="layui-form-item" v-if="checkitemType === 'variables'" v-for="ii in ckConfig.SAMPLE_VOLUME">
		<div class="layui-inline">
			<label class="layui-form-label input-lab">样本{{ii+1}}</label> 
			<div class="layui-input-inline input-cls">
				<input type="text" class="layui-input input-cls" name="add_sample_data" id="add_sample_{{ii+1}}">
			</div>
		</div>
	</div>
	<div class="layui-form-item" v-if="checkitemType === 'counting'">
		<div class="layui-inline">
			<label class="layui-form-label input-lab">抽检数</label> 
			<div class="layui-input-inline">
				<input type="text" class="layui-input input-cls" id="add_check_count" name="add_check_count">
			</div>
		</div>
	</div>
	<div class="layui-form-item" v-if="checkitemType === 'counting'" v-for="(ii,jj) in badType">
		<div class="layui-inline">
			<label class="layui-form-label input-lab">{{jj}}</label> 
			<div class="layui-input-inline input-cls">
				<input type="text" class="layui-input input-cls" name="add_sample_data" id="add_sample_{{ii}}">
			</div>
		</div>
	</div>
	<div class="layui-form-item" align="center">
    	<div class="layui-inline layui-form" >
			<input type="checkbox" name="add_isSampleData" id="add_isSampleData" value="1" title="是否为样本">
    	</div>
    </div>
	<div class="layui-form-item" style="text-align: center;">
		<button type="button"  class="layui-btn" @click="savAddData">保存</button>
	</div>
</div>
<iframe id="hideIframe" name="hideIframe" width="0" height="0" style="display: none"></iframe>
<script type="text/html" id="operatorBar">
	<a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
	<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
</script>
<script type="text/html" id="stateTpl">
	{{#  if(d.STATE === '异常'){ }}
    	<span style="color:red;cursor: pointer;" lay-event="openViewState">{{ d.STATE }}</span>
	{{#  } else if(d.STATE === '已处理') { }}
    	<span style="color:green;cursor: pointer;" lay-event="openViewState">{{ d.STATE }}</span>
	{{#  } else { }}
    	{{ d.STATE }}
    {{#  } }}
</script>
<script type="text/html" id="sampleTpl">
	{{#  if(d.IS_SAMPLE === 'Y'){ }}
		是
	{{#  } else { }}
		否
	{{#  } }}
</script>
<script type="text/javascript">
var request = function (paras) {
	if (this.url_paraObj == undefined) {
		var search = window.location.search;
		if (search) {
			search = search.substring(1);
		}
		var paraString = search.split("&");
		this.url_paraObj = {}
		for (var i = 0; i < paraString.length; i++) {
			var index = paraString[i].indexOf("=");
			try {
				this.url_paraObj[paraString[i].substring(0, index)] = decodeURI(paraString[i].substring(index + 1));
			} catch (e) {
				this.url_paraObj[paraString[i].substring(0, index)] = paraString[i].substring(index + 1);
			}
		}
	 }
	 return paras ? this.url_paraObj[paras] : this.url_paraObj;
};
var vm = new Vue({
	el: "#controlChart",
	data: {
		configId: request("configId"),
		ckConfig: {},
// 		checkitemType: "",
		cl: "",
		ucl: "",
		lcl: "",
		calControlDiv:"",
		configDiv:"",
		addDataDiv:"",
		selectDataDiv:"",
		scDate:"",
		isSample:"",
		remark1:"",
		remark2:"",
		remark3:"",
		badType: {},	//不良种类
		badTotal: 0,	//不良总数
		sampleData: [],	//表格样本数据
		calcId:"",//单个数据id
		curEditCalcId:""
	},
	init: function() {
		var _self = this;
		this.$nextTick(function() {
			this.$http.post("../../spc/controlchart/getBaseInfo",{
				configId : request("configId")
			},{emulateJSON: true}).then(function(res){
				_self.ckConfig = res.body.ckConfig;
				_self.searchData(_self);
				_self.renderTab();
			});
		});
	},
	methods: {
		renderTab: function() {
			layui.use(["element"], function() {
				var element = layui.element;
				element.on('tab(tabFilter)', function(data) {
					var iframe = data.elem.find(".layui-tab-item.layui-show iframe")[0];
					var iVm = iframe.contentWindow.vm;
					iVm && typeof iVm.resizeChart === "function" && iVm.resizeChart();
				});
			});
		},
		renderTable: function(_self, data) {
			layui.use(['form','table','laydate'], function(){
				var table = layui.table;
				var laydate = layui.laydate;
				var form = layui.form;
				var ckType = _self.ckConfig.CHECKITEM_TYPE;	//检测项目类型
				var sampleVolume = _self.ckConfig.SAMPLE_VOLUME;	//样本容量
				var graphType = _self.ckConfig.GRAPH_TYPE;	//图类
				var cols1 = [{type:'numbers',fixed:'left',title:'序号'}
			      ,{field: 'CHECKTIME', title: '抽检时间',align:'center', width: 160}
			      ];
				var cols2 = [];
				if(graphType === "nP" || graphType === "P" 
						|| graphType === "U" || graphType === "C"){	//计数型
					cols2.push({field: 'CHECK_COUNT', title: '抽检数',align:'center'});
					var badType = _self.badType;
					$.each(badType || {}, function(k, v) {
						cols2.push({field: 'badValue_' + k, title: v,align:'center'});
					});
				} else {	//计量型
					cols2 = [{field: 'REMARK1', title: '设备',align:'center'}
 			      ,{field: 'REMARK2', title: '位置',align:'center'}
 			      ,{field: 'REMARK3', title: '管号',align:'center'}]; 
					for(var i = 1; i <= sampleVolume; i++){
						cols2.push({field: 'SAMPLE_' + i, title: '样本' + i,align:'center'});
					}
					
				}
				var cols3 = [];
				if(graphType === "nP" || graphType === "P" 
						|| graphType === "U" || graphType === "C"){	//计数型
					var field = "", title = "";
					if(graphType === "nP"){
						field = "BADCOUNT";
						title = "不合格品数";
					}
					if(graphType === "C"){
						field = "BADCOUNT";
						title = "缺陷数";
					}
					if(graphType === "P"){
						field = "badRate";
						title = "不合格品率(%)";
					}
					if(graphType === "U"){
						field = "badRate";
						title = "缺陷率(%)";
					}
					cols3 = [{field: 'GRAPH_TYPE', title: '状态',align:'center',templet:'#stateTpl'}
					,{field: field, title: title,align:'center'}];
				} else {	//计量型
					cols3 = [{field: 'STATE', title: '状态',align:'center',templet:'#stateTpl'}
					,{field: 'AVG', title: '平均值',align:'center'}
					,{field: 'RANGE', title: '极差值',align:'center'}
					,{field: 'STANDARD_DEVIATION', title: '标准差',align:'center'}
					,{field: 'MAX_VALUE', title: '最大值',align:'center'}
					,{field: 'MIN_VALUE', title: '最小值',align:'center'}];
				}
				var cols4 = [{field: 'IS_SAMPLE', title: '是否为样本',width:100,align:'center',templet:'#sampleTpl'},
				{fixed: 'right',title:'操作', align:'left',width:130,toolbar: '#operatorBar'}];
				table.render({
					id: 'sampleDataTable'
					,elem: '#sampleDataTable'
				    ,height: $('.div-grid').height()-38  //'full - 0'
				    ,cols: [ //标题栏
				    	_.concat(cols1, cols2, cols3,cols4)
				    ]
					,limit: 10
					,limits: [10, 20, 50, 100]
				    ,data: data
				    ,page: true //是否显示分页
				    ,done: function(res, curr, count) {
				    	
					}
				});
				//表格点击事件
				table.on('tool(sampleDataFilter)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					var row = obj.data //获得当前行数据
					var layEvent = obj.event; //获得 lay-event 对应的值
                    if("openViewState" == layEvent){
                    	_self.openViewState(row, obj);//查看判异异常信息
                    }
                    //监听工具条
					if("update" === layEvent){
						_self.curEditCalcId = row.EMESQ_SPC_SAMPLE_CALC_ID;
						$("#add_check_date").val(row.CHECKTIME);
						if(graphType === "nP" || graphType === "P" || graphType === "U" || graphType === "C"){	//计数型
							$("#add_check_count").val(row.CHECK_COUNT);
							var badType = _self.badType;
							$.each(badType || {}, function(k, v) {
								$("#add_sample_"+ k).val(row['badValue_'+k]);
							});
						} else {	//计量型
							for(var i = 1; i <= sampleVolume; i++){
								$("#add_sample_"+i).val(row['SAMPLE_'+i]);
							}
						}			
						if(row.IS_SAMPLE=='N'){
							$("#add_isSampleData").removeAttr("checked");
						}else{
							$("#add_isSampleData").attr("checked","checked");
						}
						form.render('checkbox');			
						_self.openAddData(_self);
					}
					if("delete" === layEvent){
						layer.confirm('是否确认删除?', function(index){
						  _self.delCalData(_self,row.EMESQ_SPC_SAMPLE_CALC_ID);
						  layer.close(index);
						});
					}
				});
				//表格渲染完后，再加载图表
				if(graphType=='XR'){
		    		$("#control").attr("src", "xrChart.html");
                }else if(graphType=='XS'){
                    $("#control").attr("src", "xsChart.html");
				}else if(graphType=='IMR'){
                    $("#control").attr("src", "imrChart.html");
                }else{
                    $("#control").attr("src", "chart_control_counting.html");
				}
		    	$("#sampleRunning").attr("src", "chart_sample_running.html");
		    	$("#averageRunning").attr("src", "chart_average_running.html");
		    	$("#plato").attr("src", "chart_plato.html");
		    	$("#cpkAnalysisChart").attr("src", "cpkChart.html");
                $("#normalCheckChart").attr("src", "normalDistCheckChart.html");
                $("#cpkPredictChart").attr("src", "cpkPredictChart.html");
                $("#cpkCyclePredictChart").attr("src", "cpkCyclePredictChart.html");
			});
		},
		searchData: function(_self){
			_self = _self.target ? this : _self;
			var loadIndex;
			layui.use('layer', function(){
				var layer = layui.layer;
				loadIndex = layer.load(1);
			});
			_self.$nextTick(function() {
				this.$http.post("../../spc/controlchart/getSampleData",{
					configId : _self.configId,
					scDate:_self.scDate,
					isSample:_self.isSample,
					remark1:_self.remark1,
					remark2:_self.remark2,
					remark3:_self.remark3
				},{emulateJSON: true}).then(function(res){
					if(res.body.result){
						_self.sampleData = res.body.sampleData;
						_self.badType = res.body.badType; //不良种类
						_self.badTotal = res.body.badTotal;	//不良总数
						_self.cl = res.body.cl;
						_self.ucl = res.body.ucl;
						_self.lcl = res.body.lcl;
						_self.$options.methods.renderTable(_self, _self.sampleData);
					}else{
						//alert(res.body.msg);
						layer.msg(res.body.msg, {time: 2000});
						_self.sampleData = [];
						//_self.$options.methods.renderTable(_self, _self.sampleData);
						layui.use(['form','table','laydate'], function(){});
						if(res.body.minDate&&res.body.maxDate){
							_self.scDate = res.body.minDate+" ~ "+res.body.maxDate;
							$("#select_check_date").val(_self.scDate);
							_self.$options.methods.searchData(_self);
						}
					}
					layer.close(loadIndex);
				});
			});
		}
		,openSelectData:function(_self){
			_self = _self.target ? this : _self;
			var selectDataDiv = layer.open({
			  type: 1,
			  area:'600px',
			  content: $('#selectDataDiv')
			  ,success:function(){
				  var laydate = layui.laydate;
				  laydate.render({
				    elem: '#select_check_date' //指定元素
				    ,range:'~'
				    ,type:'datetime'
				  });
			  }
			});
			_self.selectDataDiv = selectDataDiv;
		}
		,searchSelectData:function(_self){
			_self = _self.target ? this : _self;
			var scDate = $("#select_check_date").val();
			var isSample = $("#select_isSampleData:checked").val();
			_self.scDate = scDate;
			_self.isSample = (isSample?isSample:"0");
			_self.remark1 = $("#select_remark1").val();
			_self.remark2 = $("#select_remark2").val();
			_self.remark3 = $("#select_remark3").val();
			_self.$options.methods.searchData(_self);
			layer.close(_self.selectDataDiv);
		}
		,openAddData:function(_self){
			_self = _self.target ? this : _self;
			var addDataDiv = layer.open({
			  type: 1,
			  area:'450px',
			  content: $('#addDataDiv') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
			  ,success:function(){
				  var laydate = layui.laydate;
				  laydate.render({
				    elem: '#add_check_date' //指定元素
				    ,type:'datetime'
				  });
				  if(_self.curEditCalcId==""){
					  //清除表单数据
					  $("input[name='add_check_date']").val('');
					  $("input[name='add_sample_data']").val('');
					  $("input[name='add_check_count']").val('');
				  }
			  },
			  cancel: function(index, layero){ 
				  //清除表单数据
				  $("input[name='add_check_date']").val('');
				  $("input[name='add_sample_data']").val('');
				  $("input[name='add_check_count']").val('');
				  layer.close(index);
				  return false; 
				} 
			  
			});
			_self.addDataDiv = addDataDiv;
		}
		,savAddData:function(_self){
			_self = _self.target ? this : _self;
			var checkItemType = _self.ckConfig.CHECKITEM_TYPE;
			var graphType = _self.ckConfig.GRAPH_TYPE;
			var badTypeObj = _self.badType;
			var checkDate = $("input[name='add_check_date']").val();
			var checkCount = $("input[name='add_check_count']").val();
			var isSampleData = $("#add_isSampleData:checked").val();
			var sampleDataObjs = $("input[name='add_sample_data']");
			var sampleDataStr = "";
			var cf = true;
			if(checkDate==""){
				$("input[name='add_check_date']").focus();
				layer.msg("请填写检验时间！", {time: 1000});
				return;
			}
			if(checkItemType=="counting"&&checkCount==""){
				$("input[name='add_check_count']").focus();
				layer.msg("请填写抽检数！", {time: 1000});
				return;
			}
			if(checkItemType=="counting"&&isNaN(checkCount)){
				$("input[name='add_check_count']").focus();
				layer.msg("抽检数必须为数字！", {time: 1000});
				return;
			}
			sampleDataObjs.each(function(){
				if($(this).val()==""){
					layer.msg("请填写样本值！", {time: 1000});
					$(this).focus();
					cf = false;
					return;
				}
				if(isNaN($(this).val())){
					layer.msg("请填写数字！", {time: 1000});
					$(this).focus();
					cf = false;
					return;
				}
				sampleDataStr+=$(this).val()+",";
			});
			if(!cf)return;
			if(sampleDataStr!="")sampleDataStr = sampleDataStr.substr(0,sampleDataStr.length-1);
			var badTypeCodeStr = "";
			if(badTypeObj){
				for(var i in badTypeObj){
					badTypeCodeStr+=i+",";
				}
			}
			if(badTypeCodeStr!="")badTypeCodeStr = badTypeCodeStr.substr(0,badTypeCodeStr.length-1);
			//console.log(checkDate);
			//console.log(sampleDataStr);
			//console.log(badTypeCodeStr);
			_self.$nextTick(function() {
				this.$http.post("../../spc/controlchart/addData",{
					configId : _self.configId,
					checkDate:checkDate,
					checkCount:checkCount,
					sampleDataStr:sampleDataStr,
					badTypeCodeStr:badTypeCodeStr,
					checkItemType:checkItemType,
					graphType:graphType,
					isSample:(isSampleData?isSampleData:"0"),
					curEditCalcId:_self.curEditCalcId
				},{emulateJSON: true}).then(function(res){
					if(res.body.result){
						_self.$options.methods.searchData(_self);
						layer.close(_self.addDataDiv);
					}else{
						
					}
					_self.curEditCalcId = "";
					//清除表单数据
				    $("input[name='add_check_date']").val('');
				    $("input[name='add_sample_data']").val('');
				    $("input[name='add_check_count']").val('');
					layer.msg(res.body.msg, {time: 1000});
				});
			});
		}
		,delCalData:function(_self,calId){
			_self = _self.target ? this : _self;
			_self.$nextTick(function() {
				this.$http.post("../../spc/controlchart/delCalData",
				{configId : _self.configId,calcId : calId},{emulateJSON: true}).then(function(res){
					if(res.body.result){
						_self.$options.methods.searchData(_self);
					}
					layer.msg(res.body.msg, {time: 1000});
				});
			});
		}
		,openCalControlDiv:function(_self){
			_self = _self.target ? this : _self;
			_self.$nextTick(function() {
				this.$http.post("../../spc/controlchart/getConfig",
				{configId : _self.configId},{emulateJSON: true}).then(function(res){
					$("#setucl").val(res.body.config.CONTROL_X_UPPER);
					$("#setlcl").val(res.body.config.CONTROL_X_LOWER);
					$("#setcltarget").val(res.body.config.CONTROL_X_VAL);
					var calControlDiv = layer.open({
					  type: 1,
					  area:'400px',
					  content: $('#calControlDiv') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
					  
					});
					_self.calControlDiv = calControlDiv;
				});
			});
			
		}
		,savCalControl:function(_self){
			_self = _self.target ? this : _self;
			_self.$nextTick(function() {
				var setucl = $("#setucl").val();
				var setlcl = $("#setlcl").val();
				var setcltarget = $("#setcltarget").val();
				if(setucl==''||setlcl==''||setcltarget==''){
					layer.msg("请输入上下限！", {time: 2000});
					return;
				}
				this.$http.post("../../spc/controlchart/savCalControl",{
					configId : _self.configId,
					ucl:setucl,
					lcl:setlcl,
					target:setcltarget
				},{emulateJSON: true}).then(function(res){
					layer.msg(res.body.msg, {time: 2000});
					if(res.body.result){
						layer.close(_self.calControlDiv);
						_self.$options.methods.searchData(_self);
					}
				});
			});
		}
		,calControl:function(){
			var _self = this;
			_self.$nextTick(function() {
				this.$http.post("../../spc/ckConfig/calControl",{
					configId : _self.configId,
					graphType : _self.ckConfig.GRAPH_TYPE
				},{emulateJSON: true}).then(function(res){
					if(res.body.result){
						$("#setucl").val(res.body.calData.UCL);
						$("#setcltarget").val(res.body.calData.CL);
						$("#setlcl").val(res.body.calData.LCL);
					}else{
						layer.msg(res.body.msg, {time: 2000});
					}						
				});
			});
		}
		,openSetConfigDiv:function(_self){
			_self = _self.target ? this : _self;
			_self.$nextTick(function() {
				this.$http.post("../../spc/controlchart/getConfig",
				{configId : _self.configId},{emulateJSON: true}).then(function(res){
					$("#setusl").val(res.body.config.SPECIFICA_UPPER);
					$("#setlsl").val(res.body.config.SPECIFICA_LOWER);
					$("#settarget").val(res.body.config.TARGET_VAL);
					var configDiv = layer.open({
					  type: 1,
					  area:'400px',
					  content: $('#setConfigDiv') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
					  
					});
					_self.configDiv = configDiv;
				});
			});
			
		}
		,savSetConfig:function(_self){
			_self = _self.target ? this : _self;
			_self.$nextTick(function() {
				var setusl = $("#setusl").val();
				var setlsl = $("#setlsl").val();
				var settarget = $("#settarget").val();
				if(setusl==''||setlsl==''||settarget==''){
					layer.msg("请输入上下限！", {time: 2000});
					return;
				}
				this.$http.post("../../spc/controlchart/setConfig",{
					configId : _self.configId,
					usl:setusl,
					lsl:setlsl,
					target:settarget
				},{emulateJSON: true}).then(function(res){
					layer.msg(res.body.msg, {time: 2000});
					if(res.body.result){
						layer.close(_self.configDiv);
						_self.$options.methods.searchData(_self);
					}
				});
			});
		}
		,executeCheckRule:function(_self){
			_self = _self.target ? this : _self;
			var loadIndex;
			layui.use('layer', function(){
				var layer = layui.layer;
				loadIndex = layer.load(1);
			});
			var scDate = $("#select_check_date").val();
			var isSample = $("#select_isSampleData:checked").val();
			_self.scDate = scDate;
			_self.isSample = (isSample?isSample:"0");
			_self.remark1 = $("#select_remark1").val();
			_self.remark2 = $("#select_remark2").val();
			_self.remark3 = $("#select_remark3").val();
			
			_self.$nextTick(function() {
				this.$http.post("../../spc/controlchart/executeCheckRule",{
					configId : _self.configId,
					scDate:_self.scDate,
					isSample:_self.isSample,
					remark1:_self.remark1,
					remark2:_self.remark2,
					remark3:_self.remark3
				},{emulateJSON: true}).then(function(res){
					layer.msg(res.body.msg, {time: 2000});
					if(res.body.result){
						layer.close(_self.configDiv);
						_self.$options.methods.searchData(_self);
					}
					layer.close(loadIndex);
				});
			});
		}
		,doExportExcel:function(_self){
			var configId = this.configId;
			var scDate = $("#select_check_date").val();
			var isSample = $("#select_isSampleData:checked").val();
			isSample = (isSample?isSample:"0");
			var remark1 = $("#select_remark1").val();
			var remark2 = $("#select_remark2").val();
			var remark3 = $("#select_remark3").val();
			var remark4 = $("#select_remark4").val();
			var remark5 = $("#select_remark5").val();
			var paramaData = {configId:configId,scDate:scDate,isSample:isSample,remark1:remark1,remark2:remark2,
			remark3:remark3,remark4:remark4,remark5:remark5};
			window.open("../../spc/controlchart/doExportExcel?"+$.param(paramaData),"hideIframe");
		}
		,openViewState:function(row){
        	var calcId = row.EMESQ_SPC_SAMPLE_CALC_ID;
        	var _self = this;
        	_self.calcId = calcId;
			_self.$nextTick(function() {
				this.$http.post("../../spc/ckConfig/viewCheckRs",{
					calcId : calcId
				},{emulateJSON: true}).then(function(res){
			      	//示范一个公告层
			      	layer.open({
			        type: 1
			        ,area: '600px;'
			        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
			        ,btn: ['确定', '处理']
			        ,btnAlign: 'c'
			        ,moveType: 1 //拖拽模式，0或者1
			        ,content: $('#viewStateDiv')
			        ,success: function(layero){
			        	  var graphType = _self.ckConfig.GRAPH_TYPE;	//图类
			        	  var badType = _self.badType;//不良类型
			        	  var sdc = "";
			        	  if(graphType === "nP" || graphType === "P" || graphType === "U" || graphType === "C"){	//计数型
								var field = "", title = "";
								if(graphType === "nP"){
									field = "BADCOUNT";
									title = "不合格品数";
								}
								if(graphType === "C"){
									field = "BADCOUNT";
									title = "缺陷数";
								}
								if(graphType === "P"){
									field = "badRate";
									title = "不合格品率(%)";
								}
								if(graphType === "U"){
									field = "badRate";
									title = "缺陷率(%)";
								}
								
								sdc+="抽检数："+row.CHECK_COUNT+"<br/>";
								for(var bt in badType){
									sdc+=row['badName_'+bt]+"："+row['badValue_'+bt]+"<br/>";
								}
								sdc+= title+"："+row[field]+"<br/>";
							}else{
								sdc = "样本数据："+row.SUBGROUP+"<br/>";
					          	sdc+= "平均值："+row.AVG+"<br/>";
					          	sdc+= "极差值："+row.RANGE+"<br/>";
					          	sdc+= "标准差："+row.STANDARD_DEVIATION+"<br/>";
					          	sdc+= "最大值："+row.MAX_VALUE+"<br/>";
					          	sdc+= "最小值："+row.MIN_VALUE+"<br/>";
							}
				          $("#sampleDataC").html(sdc);
				          var edc = "失控信息：<br/>"+res.body.ERROR_INFO+"<br/>";
				          if(res.body.REASON)
				          edc+="失控原因：<br/>"+res.body.REASON+"<br/>";
				          if(res.body.HANDLE_INFO)
				          edc+="处理措施："+res.body.HANDLE_INFO+"<br/>";
				          if(res.body.HANDLE_USER_NAME)
				          edc+="处理人："+res.body.HANDLE_USER_NAME+"<br/>";
				          if(res.body.HANDLE_TIME)
				          edc+="处理时间："+res.body.HANDLE_TIME+"<br/>";
				          $("#errorDataC").html(edc);
			        }
			        ,btn2: function(index, layero){
						_self.openHandleError(res.body.REASON,res.body.HANDLE_INFO);
					    return false;
					 }
			      });
				});
			});
        }
        ,openHandleError:function(reason,handleInfo){
        	layer.open({
			  type: 1,
			  area:'600px',
			  content: $('#handleErrorDiv') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
			  ,success:function(){
			  	$("#unControlReason").val("");
			  	$("#handleMethod").val("");
			  	if(reason)$("#unControlReason").val(reason);
			  	if(handleInfo)$("#handleMethod").val(handleInfo);
			  }
			});
        }
        ,handleError:function(_self){//处理措施
        	_self = _self.target ? this : _self;
        	var unControlReason = $("#unControlReason").val();//原因
        	var handleMethod = $("#handleMethod").val();//处理方法
        	if(!unControlReason||unControlReason.length==0){
        		layer.msg("请填写失控原因！", {time: 2000});
        		return;
        	}
        	if(!handleMethod||handleMethod.length==0){
        		layer.msg("请填写处理方法！", {time: 2000});
        		return;
        	}
			_self.$nextTick(function() {
				this.$http.post("../../spc/ckConfig/handleError",{
					calcId : _self.calcId,
					unControlReason:unControlReason,
					handleMethod:handleMethod
				},{emulateJSON: true}).then(function(res){
					layer.msg(res.body.msg, {time: 2000});
					if(res.body.result){
						layer.closeAll();
						_self.$options.methods.searchData(_self);
					}
				});
			});
        }
	},
	computed: {
		checkitemType: function() {
			var gt = this.ckConfig.GRAPH_TYPE;
			if(gt === "nP" || gt === "P" || gt === "U" || gt === "C"){
				return "counting";
			} else {
				return "variables";
			}
		}
	}
});
</script>
</html>